import pytest
import requests
import logging
class TestCreate01():
    token=None
    def test_login(self):#登录
        url="http://10.59.9.12:7001/api/public/login"
        body={"username":"13811033962","password":"123456"}
        r=requests.post(url=url,json=body)
        print(r.json())
        TestCreate01.token="Bearer "+r.json()["data"]["token"]
        assert r.status_code==200
        logging.info(r.json())
    def test_ck(self):
        url="http://10.59.9.12:7001/api/goods/view?id=32"
        r=requests.get(url=url)
        print(r.json())
        assert r.status_code == 200
        logging.info(r.json())
    def test_add(self):
        url="http://10.59.9.12:7001/api/cart/add"
        headers={"auth-token":TestCreate01.token}
        body={"id":32,"sku_id":"","num":1}
        r=requests.post(url=url,headers=headers,json=body)
        print(r.json())
        assert r.status_code == 200
        logging.info(r.json())
    def test_wrdd(self):
        url="http://10.59.9.12:7001/api/order/confirm?id=316&type=cart&shipping_type=1"
        headers={"auth-token":TestCreate01.token}

        r=requests.get(url=url,headers=headers)
        print(r.json())
        assert r.status_code == 200
        logging.info(r.json())

    def test_tjdd(self):
        url = "http://10.59.9.12:7001/api/order/create"
        headers = {"auth-token": TestCreate01.token}
        body={"id":"316",
              "type":"cart",
              "address_id":15,
              "store_id":1,
              "shipping_type":1,
              "bonus_id":"0",
              "payment":"balance",
              "remarks":"",
              "source":1,
              "url":"http://10.59.9.12:7001/wap/pages/cart/confirm?id=316&type=cart"}

        r = requests.post(url=url, headers=headers,json=body)
        print(r.json())
        assert r.status_code == 200
        logging.info(r.json())

